using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/**
生成球，控制球
触摸移动球
**/
public class Ball : MonoBehaviour
{
    // 球预制体
    public GameObject BallPrefab { get; private set; }
    // 球实例
    public GameObject BallInstance { get; private set; }

    public void Awake()
    {
        BallPrefab = Resources.Load<GameObject>("Prefabs/Ball");
    }

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }
    // 生成球
    public void GenerateBall(Vector3 currentPosition)
    {
        //&& BallInstance == null
        if (BallPrefab != null && BallInstance == null)
        {
            BallInstance = Instantiate(BallPrefab, currentPosition, Quaternion.identity); // 指定位置和旋转
            BallInstance.name = "MyBall"; // 可选，设置实例的名字
            Rigidbody ballRigidbody = BallInstance.GetComponent<Rigidbody>();
            ballRigidbody.useGravity = false;
            ballRigidbody.velocity = Vector3.zero;
        }
    }
}
